import { createWriteStream } from 'fs';
import { app } from 'electron';
import { join } from 'path';

const noval = {
    writeNoval: function writeNoval(name,data) {
        const userDataPath = app.getPath('userData'); // 获取用户数据目录
        const filePath = join(userDataPath, name); // 构建文件路径
        console.log('构建文件路径', filePath);
        // const str = data; // 要写入的内容
        // for (let i = 0; i < data.noval.length; i++) {
        //     str += data.noval[i].title
        //     str += data.noval[i].content
        // }
        const writeStream = createWriteStream(filePath);

        writeStream.write(data);
        writeStream.end();

        writeStream.on('finish', () => {
            console.log('写入文件成功！');
        });

        writeStream.on('error', (error) => {
            console.error('写入文件时出错：', error);
        });

    }
}

export { noval };
